package com.vhall.component.controller.notice;


import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.notice.facade.NoticeFacade;
import com.vhall.component.controller.room.facade.RoomInnerFacade;
import com.vhall.component.entity.notice.vo.NoticeListRspVo;
import com.vhall.component.entity.notice.vo.NoticeListVO;
import com.vhall.component.entity.notice.vo.SendNoticeReqVo;
import com.vhall.component.entity.room.dto.RoomsEntityDTO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.framework.common.exception.BusinessException;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.plugin.common.exception.BizErrorCode;
import com.vhall.component.plugin.common.support.VssToken;
import com.vhall.component.plugin.common.support.VssTokenThreadLocal;
import com.vhall.component.service.notice.NoticesService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xianglei
 * @date 2021/6/9 15:47
 */
@VhallComponent
public class NoticeController implements NoticeFacade {

    @Autowired
    private NoticesService noticesService;

    @Autowired
    private RoomInnerFacade roomInnerFacade;

    @VssTokenAuth
    @Override
    public NoticeListRspVo noticeLists(NoticeListVO reqVO) {
        RoomsEntityDTO roomInfo = roomInnerFacade.getRoomInfo(reqVO.getRoomId());
        if (roomInfo == null) {
            throw new BusinessException(BizErrorCode.EMPTY_ROOM);
        }
        return noticesService.list(reqVO);
    }

    @Override
    @VssTokenAuth
    public JSONObject sendNotice(SendNoticeReqVo reqVo) {
        RoomsEntityDTO roomInfo = roomInnerFacade.getRoomInfo(reqVo.getRoomId());
        if (roomInfo == null) {
            throw new BusinessException(BizErrorCode.EMPTY_ROOM);
        }
        VssToken token = VssTokenThreadLocal.getToken();
        return noticesService.sendNotices(token.getThirdPartyUserId(), reqVo);
    }


}
